window.fbAsyncInit = function() {
  FB.init({
    appId      : '173632299487747', // App ID
    channelUrl : 'http://adam.lifemakesuslaugh.com/facebook/channel.html', // Channel File
    status     : true, // check login status
    cookie     : true, // enable cookies to allow the server to access the session
    xfbml      : true  // parse XFBML
  });

  FB.Event.subscribe('auth.authResponseChange', function(response) {
    if (response.status === 'connected') {
      facebookReady();
    } else if (response.status === 'not_authorized') {    
      FB.login();
    } else {
      FB.login();
    }
  });
};

// Load the SDK asynchronously
(function(d){
  var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
  if (d.getElementById(id)) {return;}
  js = d.createElement('script'); js.id = id; js.async = true;
  js.src = "http://connect.facebook.net/en_US/all.js";
  ref.parentNode.insertBefore(js, ref);
}(document));

function facebookReady() {
  console.log('Welcome!  Fetching your information.... ');
  FB.api('/me', function(response) {
    console.log('Good to see you, ' + response.name + '.');
  });
  FB.api({
    method: 'fql.query',
    query: 'SELECT url FROM square_profile_pic WHERE id IN (SELECT uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())) AND size = 100',
  }, initGame);
}